package com.ithema.domain;

import com.ithema.exception.AgeOutOfBoundsException;

import java.io.Serializable;

//继承的设计最好满足客观上的is a关系
public class People implements Serializable {
    private String id;          //学号
    private String name;        //姓名
    private String age;         //年龄
    private String birthday;    //出生日期

    private static final long serialVersionUID = 8683452581122892189L;

    public People() {
    }

    public People(String id, String name, String age, String birthday) {
        this.id = id;
        this.name = name;
        this.birthday = birthday;
        if (Integer.parseInt(age) < 80 && Integer.parseInt(age) >=18){
            this.age = age;
        }else{
            //抛出: 年龄越界异常
            throw new AgeOutOfBoundsException("年龄数值越界: 有效范围[18,80]");
        }
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {  //heima001
        this.id = id;  //this.id = heima001
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        if (Integer.parseInt(age) < 80 && Integer.parseInt(age) >=18){
            this.age = age;
        }else{
            //抛出: 年龄越界异常
            throw new AgeOutOfBoundsException("年龄数值越界: 有效范围[18,80]");
        }
    }

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        return id+","+name+","+age+","+birthday;
    }
}
